/*************************************
* @update: 2021-06-23   LiLinBin  [创建文件]
*
* @description: 属性配置,数据配置等等,布局用到的公用参数
****************************************/

export default {
    data: () => ({
        accordion: true,            //是否开启手风琴
        labelCol: { span: 8 },      //label标签占的份数
        wrapperCol: { span: 16 },   //value内容占的份数
        labelAlign: "right",         //label标签默认对齐方式

        width: '300px',
        activeKey: ['1'],
        showConfigData: T.isTestVersion,

        myAttrConfig: [],
        attrConfigStr: '',

        initFlag: false
    }),
    computed: {},
    watch: {
        attrConfig: {
            handler (newAttr) {
                this.myAttrConfig = _.cloneDeep(newAttr)
                this.attrConfigStr = JSON.stringify(this.myAttrConfig, null, 2)
            },
            deep: true
        }
    },
    created () {
        this.init()
    },
    mounted () { },
    methods: {
        init () {
            //这里为了兼容旧代码而增加的
            if (this.initFlag) return
            this.initFlag = true

            this.initData()
        },

        initData () {
            this.myAttrConfig = _.cloneDeep(this.attrConfig || [])
            this.attrConfigStr = JSON.stringify(this.myAttrConfig, null, 2)
        },

        updateConfig () {
            const newConfig = (new Function(`return ${this.attrConfigStr.trim()}`))() || []

            if (newConfig.length === 0) {
                this.$confirm({
                    content: '您确定要清空配置数据吗?',
                    onOk: () => {
                        this.myAttrConfig = newConfig
                    },
                    onCancel: () => { }
                })
            } else {
                this.myAttrConfig = newConfig
                this.$message.success('修改成功!')
            }
        }

    },
    beforeUnmount () { }
}